import java.util.Vector;

public class EnemyTank extends Tank implements Runnable{
    EnemyTank(int x, int y) {
        super(x, y);
        setType(1);
        setDir(2);
    }
    @Override
    public void run(){
        int d = (int)(Math.random() * 5);
        int t = (int)(Math.random() * (d < 4 ? 20 : 5)) + 1;
        while(true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(d < 4) this.setDir(d);
            if(t > 0){
                t --;
                switch (d){
                    case 0:
                        this.up();
                        break;
                    case 1:
                        this.left();
                        break;
                    case 2:
                        this.down();
                        break;
                    case 3:
                        this.right();
                }
            }else{
                d = (int)(Math.random() * 5);
                t = (int)(Math.random() * 15);
                if(d < 1){
                    if(this.getY() > 400) t ++;
                }else if(d < 2){
                    if(this.getX() > 650) t ++;
                }else if(d < 3){
                    if(this.getY() <= 400) t ++;
                }else if(d < 4){
                    if(this.getX() <= 650) t ++;
                }else t -= 10;
            }
            if((int)(Math.random() * 100) < 1){
                this.attack();
            }
        }
    }
}
